from flask import Flask,render_template,jsonify,request,redirect

# __name__代表模块名，当模块被引用时，__name__将不是__main__，而是模块名
# 创建一个Flask对象，参数为模块名
#template_folder指定模板文件所在的目录

app =   Flask(__name__,template_folder='templates')
@app.route('/login',methods=['GET','POST'])
def login():
    if request.method == 'GET':
      
    # return '登录' #httpresponse
        return render_template('login.html') #render
    # return jsonify({'name':'zhangsan','age':18}) #jsonresponse
    
    user = request.form.get('user')
    pws = request.form.get('pwd') 

    if user=='admin' and pws=='123':
        return redirect('/index')
    error = '用户名或密码错误'
   
    return render_template('login.html',error=error)       

@app.route('/index') 
def index(): 
    return '首页'

if __name__ == '__main__':
    app.run(debug=True)
